#include "PreCompile.hpp"

#include "IncludeDirective.hpp"
#include "Tokenizer.hpp"

namespace CPreProc
{
  // see c standard, paragraph 6.4 and 6.10.2

  IncludeDirective::IncludeDirective(Tokenizer &tokenizer,bool directive_read)
  {
    assert(directive_read);   // not implemented yet

    tokenizer.skip_optional_whitespace();

    Token header_name;
    if(tokenizer.try_read_header_name(header_name))
    {
      file_name = header_name.to_string();
      if(header_name.get_token_id() == HeaderNameType_Quoted)
        type = Type_Quoted;
      else
        type = Type_AngularBrackets;
    }
    else
    {
      assert(!"not implemented yet");
    }
  }

  Glib::RefPtr<IncludeDirective> IncludeDirective::parse(Tokenizer &tokenizer,bool directve_read)
  {
    return Glib::RefPtr<IncludeDirective>(new IncludeDirective(tokenizer,directve_read));
  }

  void IncludeDirective::process(PreProcessorContext &context) const
  {
    Glib::RefPtr<PreProcFile> included_file;

    switch(type)
    {
    case Type_Quoted:
      included_file = context.load_include_file(file_name,IncludeSearchType_Quoted);
      break;
    
    case Type_AngularBrackets:
      included_file = context.load_include_file(file_name,IncludeSearchType_AngularBrackets);
      break;

    case Type_PPTokens:
      break;
    }
  }
}

